package com.aerozhonghuan.oknet2;

import java.lang.ref.WeakReference;

import okhttp3.Call;
import okhttp3.Callback;

/**
 * Created by zhangyunfei on 17/7/12.
 */

public class OkNetCall {
    private WeakReference<Call> callWeakReference;

    public OkNetCall(Call call) {
        this.callWeakReference = new WeakReference<>(call);
    }


    /**
     * Cancels the request, if possible. Requests that are already complete cannot be canceled.
     */
    public void cancel() {
        if (geCallObject() == null) return;
        geCallObject().cancel();
    }

    /**
     * Returns true if this call has been either  executed}
     */
    public boolean isExecuted() {
        if (geCallObject() == null) return false;
        return geCallObject().isExecuted();
    }

    public boolean isCanceled() {
        if (geCallObject() == null) return true;
        return geCallObject().isCanceled();
    }

    private Call geCallObject() {
        return callWeakReference == null ? null : callWeakReference.get();
    }
}
